import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: XXHH
 * @CreateTime: 2025-05-05
 */
class MyThreadPool{
    private BlockingQueue<Runnable> queue = null;
    public MyThreadPool(int n){
        queue = new ArrayBlockingQueue<>(1000);
        // 创建 n 个线程
        for (int i = 0;i<n;i++){
            Thread t = new Thread(()->{
                try {
                    while (true) {
                        Runnable task = queue.take();
                        task.run();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
//            t.setDaemon(true);
            t.start();
        }
    }
    // 提交任务
    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }


}
public class Demo45 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool threadPool = new MyThreadPool(10);
        for (int i = 0; i <1000; i++) {
            int id = i;
            threadPool.submit(()->{
                System.out.println("Hello "+id+","+Thread.currentThread().getName());
            });
        }
    }
}
